package com.etlmaster.datax.plugins.reader.directoryReader;

import java.util.List;

import com.dp.nebula.wormhole.common.interfaces.IParam;
import com.dp.nebula.wormhole.common.interfaces.IReaderPeriphery;
import com.dp.nebula.wormhole.common.interfaces.ISourceCounter;
import com.dp.nebula.wormhole.common.interfaces.ITargetCounter;
import com.etlmaster.datax.common.utils.FileScanInfo;
import com.etlmaster.datax.common.utils.FileScaner;
import com.etlmaster.datax.plugins.tranformer.LineTransFormer;

public class DirectoryReaderPeriphery  implements IReaderPeriphery{

	private  String directoryPath;
	
	private  String regex;
	
	private  Boolean  isScanDepth ;
	

	public static List<FileScanInfo> foundFiles;
	private void init(IParam param) {
		this.directoryPath = param.getValue(ParamKey.directoryPath, "");
		this.regex = param.getValue(ParamKey.regex, "");
		this.isScanDepth = param.getBooleanValue(ParamKey.isScanDepth,false);
	}
	public void prepare(IParam param, ISourceCounter counter) {
		init(param);
		FileScaner scaner=new FileScaner();
		scaner.setPath(directoryPath);
		scaner.setRegex(regex);
		scaner.setIsDepthwise(isScanDepth);
		scaner.scanAndCheckResult();
		foundFiles=scaner.foundFiles;
		
	}

	public void doPost(IParam param, ITargetCounter counter) {
		LineTransFormer.clearAll();
		
	}

}
